package dtrs;

import soenudp.UDPException;

public class DTRSMainTOR
{
    public static void main(String[] args) //arg[1] = MTL or TOR
    {   
        DTRSManager drtsManager = new DTRSManager();
        
        
        /* java DTRSMain Leader TOR */
        /* java DTRSMain Replica MTL ... and so on */
        
        String type; // MTL or TOR -> args[1]
        if (args.length > 1) 
            type = args[1]; 
        else
            type = "TOR"; // Use MTL by default just to be able to start it
                          // without and command line arguments. Node Group (type) will be mandatory
                          // in the final version. 
        try
        {
            drtsManager.doLeader(type, 1);
        } 
        catch (UDPException e)
        {
            e.printStackTrace();
        }        
        
        /*
         * Will remove the comments once 
         * dtrsManager have the appropriate condition
         * in his while() loop to check isLeader
         * 
         * 
        if (args[0].equals("Leader") || allwaysBeLeader)
        {
            try
            {
                drtsManager.doLeader(type, 1);
            } 
            catch (UDPException e)
            {
                e.printStackTrace();
            }
        }
        else if (args[0].equals("Replica"))
        {
            // Replica...
            
            // Here, dont't implement the replica...
            // You switch the unicastSocket with a groupSocket instead.
             
            // It might get a bit more complicated for sending reply to the leader but 
            // for the concern of replicating, it must share the same code than 
            // doLeader() but with a groupSocket. 
            
            // drtsManager.doReplica(type, 3, passive - 4);
        }
        */

    }
}
